import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'

export default defineConfig({
  plugins: [
    react()
  ],
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'avc-ui',
      fileName: (format) => {
        if (format === 'es') return 'avc-ui.es.js'
        if (format === 'cjs') return 'avc-ui.umd.cjs'
        return `avc-ui.${format}.js`
      },
      formats: ['es', 'cjs']
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM'
        },
        exports: 'named'
      }
    },
    outDir: 'dist'
  },
  server: {
    open: '/component-docs', // 开发服务器启动时打开组件文档页面
    fs: {
      allow: ['..'] // 允许访问父目录的文件
    }
  },
  resolve: {
    alias: {
      '@components': resolve(__dirname, 'src/components') // 添加组件路径别名
    }
  },
  // 添加对 Markdown 文件的处理
  assetsInclude: ['**/*.md']
})